<?php
/*
 module:		红娘管理
 create_time:	2022-03-08 11:13:01
 author:		
 contact:		
*/

namespace app\backend\service;

use app\backend\model\ZhMatchmakerLevel;
use app\backend\model\Member;
use app\backend\model\ZhMatchmaker;
use think\exception\ValidateException;
use xhadmin\CommonService;

class ZhMatchmakerLevelService extends CommonService
{


    /*
     * @Description  列表数据
     */
    public static function indexList($where, $limit, $page)
    {
        try {
            $res = ZhMatchmakerLevel::where($where)->order(['createtime' => 'desc'])->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return ['rows' => $res['data'], 'total' => $res['total']];
    }

    public static function byId($id)
    {
        try {
            $res = ZhMatchmakerLevel::where(['id'=>$id])->find();
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return $res;
    }

    /*
     * @Description  修改
     */
    public static function update($data)
    {
        try {
            validate(\app\backend\validate\ZhMatchmakerLevel::class)->scene('update')->check($data);
            $data['createtime'] = strtotime($data['createtime']);
            $res                = ZhMatchmakerLevel::update($data);
        } catch (ValidateException $e) {
            throw new ValidateException ($e->getError());
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        if (!$res) {
            throw new ValidateException ('操作失败');
        }
        return $res;
    }


}

